<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>
<script>

    function preview(oper) {
        //alert(oper);
        // window.print();

        var headHtml = "<head><style type='text/css' media='print'> @page{ size:  auto;   /* auto is the initial value */margin: 0mm;  /* this affects the margin in the printer settings */}html{/*background-color: #FFFFFF; */margin: 0px;  /* this affects the margin on the html before sending to printer */}</style></head><body>"

        var bottHtml = "</body>";
        if (oper < 10) {
            pagesetup_null();
            bdhtml = window.document.body.innerHTML; //获取当前页的html代码
            sprnstr = "<!--startprint" + oper + "-->"; //设置打印开始区域
            eprnstr = "<!--endprint" + oper + "-->"; //设置打印结束区域
            prnhtml = headHtml + bdhtml.substring(bdhtml.indexOf(sprnstr) + 18); //从开始代码向后取html

            prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr)) + bottHtml; //从结束代码向前取html

            //var styleHtml =  " style = '' ";
            window.document.body.innerHTML = prnhtml;
            window.print();
            window.document.body.innerHTML = bdhtml;


        } else {
            window.print();
        }

    }


</script>
